package com.example.myapp61.xiaoye.top;

import android.app.Dialog;
import android.content.Context;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.example.myapp61.R;

import static androidx.constraintlayout.motion.utils.Oscillator.TAG;

public class Dialog_1 extends Dialog implements View.OnClickListener {
    private TextView mtitle,mmsg;
    private Button mcencel,confir;
    private String title,msg,cencel,confirm;
    private IOonCencel mIOonCencel;
    private IOonConfir mIOonConfir;

    public Dialog_1 setTitle(String title) {
        this.title = title;
        return this;
    }

    public Dialog_1 setMsg(String msg) {
        this.msg = msg;
        return  this;
    }

    /**
     * 链式操作,----点点点点m,不返回空,返回当前对象
     * @param
     */
    public Dialog_1(@NonNull Context context) {
        super(context);
    }

    public Dialog_1 setCencel(String cencel,IOonCencel IOonCencel) {
        this.cencel = cencel;
        this.mIOonCencel = IOonCencel;
        return this;
    }

    public Dialog_1 setConfirm(String confirm,IOonConfir iOonConfir) {
        this.confirm = confirm;
        this.mIOonConfir = iOonConfir;
        return this;
    }

    public Dialog_1(@NonNull Context context, int themeResId) {
        super(context, themeResId);
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_dialog_1);
        initView();
    }

    private void initView() {
        mtitle = findViewById(R.id.title);
        mmsg = findViewById(R.id.msg);
        mcencel= findViewById(R.id.cancel);
        confir = findViewById(R.id.confir);
        if (!TextUtils.isEmpty(title)&&!TextUtils.isEmpty(msg)){
            mtitle.setText(title);
            mmsg.setText(msg);
        }
        mcencel.setOnClickListener(this);
        confir.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()){
            case R.id.cancel:
                Log.i(TAG, "onClick: 取消了");
                dismiss();
                break;
            case R.id.confir:
                    mIOonConfir.oncencel(this);
                break;
        }
    }

    public interface IOonCencel{
        void oncencel(Dialog_1 dialog_1);
    }
    public interface IOonConfir{
        void oncencel(Dialog_1 dialog_1);
    }
}
